package com.house.keeper.controller;

import com.alibaba.fastjson.JSONObject;
import com.house.keeper.base.BaseController;
import com.house.keeper.base.Result;
import com.house.keeper.entity.CityArea;
import com.house.keeper.entity.vo.CityAreaVo;
import com.house.keeper.service.CityAreaService;
import lombok.extern.slf4j.Slf4j;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;

/**
 * @author zjj
 * @date 2022-05-23 14:10:08
 *
 * @description 
 */
@Slf4j
@Controller
@RequestMapping("/cityArea")
public class CityAreaController extends BaseController {

    @Autowired
    private CityAreaService cityAreaService;

    /**
      * 跳转到管理页面
      * @return
      */
    @GetMapping(value = "/view")
    @RequiresPermissions("system:cityArea:view")
    public ModelAndView view(){
        ModelAndView modelAndView = new ModelAndView();
        modelAndView.setViewName("cityArea/list");
        return modelAndView;
    }
    /**
     * 分页查询
     * @param cityAreaVo 查询条件
     * @return
     */
    @GetMapping(value = "/list")
    @RequiresPermissions("system:cityArea:list")
    @ResponseBody
    public JSONObject list(CityAreaVo cityAreaVo){
        Result result=cityAreaService.selectByPage(cityAreaVo);
        return responseJSONObject(result);
    }

    /**
     * 新增或修改
     * @param cityArea
     * @return
     */
    @PostMapping(value = "/update")
    @RequiresPermissions("system:cityArea:edit")
    @ResponseBody
    public JSONObject edit(@RequestBody CityArea cityArea){
        Result result = cityAreaService.update(cityArea);
        return responseJSONObject(result);
    }

    /**
     * 删除
     * @param id id
     * @return
     */
    @GetMapping(value = "/delete")
    @RequiresPermissions("system:cityArea:del")
    @ResponseBody
    public JSONObject edit(Integer id){
        Result result = cityAreaService.delete(id);
        return responseJSONObject(result);
    }

    /**
     * 查询
     * @param pid 查询条件
     * @return
     */
    @RequestMapping(value = "/getArea")
    @ResponseBody
    public JSONObject getArea(String pid){
        Result result=Result.success(cityAreaService.selectAllCityArea(pid));
        return responseJSONObject(result);
    }





}

